<?php
require_once 'core.php';
require_once cf\Config::path.'api/admin.php';

$view = cf\api\admin\getView( cf\param::get('vid') );
$smarty->assign('view', $view);
$smarty->assign('fk', cf\param::exist('fk') ? cf\param::asInt('fk') : false);

$name = $view['name'];
if (cf\param::exist('tid') && cf\param::exist('fk')) {
	$name = cf\api\admin\getNameByKey(cf\param::get('tid'), cf\param::get('fk'));
}

$filters = cf\api\admin\getList('view_filters',0,0,array(),null,array(),false,false,array('view_id'=>$view['id']));
$activeFilter = false;
foreach ($filters as &$filter) {
	$filter['fields'] = cf\api\admin\getList('view_filter_fields',0,0,array(),null,array(),false,false,array('filter_id'=>$filter[0]));
	if ($filter[2]) {
		$activeFilter = array('id'=>$filter[0],'fields'=>array());
	}
	foreach ($filter['fields'] as &$ffield) {
		foreach ($view['allfields'] as &$f) {
			if ($ffield[1]==$f['name']) {
				$ffield['type_id'] = $f['type_id'];
				$ffield['title'] = $f['title'];
				if ($filter[2]) {
					$activeFilter['fields'][$f['name']] = array($ffield[3],$ffield[2]);
				}
				break;
			}
		}
	}
}
$smarty->assign('filters',$filters);
$smarty->assign('activeFilter',$activeFilter);

show('list',$name);
?>